home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / golf / golf.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-04-02  |  24.6 KB  |  720 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    AutoRedraw      =   -1  'True
  4.    BackColor       =   &H00C0C0C0&
  5.    BorderStyle     =   1  'Fixed Single
  6.    Caption         =   "Golf"
  7.    ClientHeight    =   6765
  8.    ClientLeft      =   1230
  9.    ClientTop       =   1065
  10.    ClientWidth     =   6525
  11.    Height          =   7170
  12.    Icon            =   GOLF.FRX:0000
  13.    Left            =   1170
  14.    LinkTopic       =   "Form1"
  15.    MaxButton       =   0   'False
  16.    ScaleHeight     =   6765
  17.    ScaleWidth      =   6525
  18.    Top             =   720
  19.    Width           =   6645
  20.    Begin CommandButton btnHelp 
  21.       Caption         =   "Help"
  22.       Height          =   315
  23.       Left            =   4200
  24.       TabIndex        =   16
  25.       Tag             =   "/3d_inset/"
  26.       Top             =   5760
  27.       Width           =   2115
  28.    End
  29.    Begin PictureBox picReference 
  30.       AutoRedraw      =   -1  'True
  31.       AutoSize        =   -1  'True
  32.       BackColor       =   &H00C0C0C0&
  33.       FillStyle       =   0  'Solid
  34.       Height          =   6030
  35.       Left            =   6600
  36.       MousePointer    =   2  'Cross
  37.       ScaleHeight     =   400
  38.       ScaleMode       =   3  'Pixel
  39.       ScaleWidth      =   250
  40.       TabIndex        =   2
  41.       Tag             =   "/3d_inset/"
  42.       Top             =   420
  43.       Width           =   3780
  44.    End
  45.    Begin CommandButton btnNewGame 
  46.       Caption         =   "New Game"
  47.       Height          =   315
  48.       Left            =   4200
  49.       TabIndex        =   13
  50.       Tag             =   "/3d_inset/"
  51.       Top             =   5340
  52.       Width           =   2115
  53.    End
  54.    Begin CommandButton btnQuit 
  55.       Caption         =   "Club House"
  56.       Height          =   315
  57.       Left            =   4200
  58.       TabIndex        =   6
  59.       Tag             =   "/3d_inset/"
  60.       Top             =   6180
  61.       Width           =   2115
  62.    End
  63.    Begin PictureBox picBG 
  64.       AutoRedraw      =   -1  'True
  65.       AutoSize        =   -1  'True
  66.       BackColor       =   &H00008000&
  67.       FillStyle       =   0  'Solid
  68.       Height          =   6030
  69.       Left            =   180
  70.       MousePointer    =   2  'Cross
  71.       ScaleHeight     =   400
  72.       ScaleMode       =   3  'Pixel
  73.       ScaleWidth      =   250
  74.       TabIndex        =   0
  75.       Tag             =   "/3d_inset/"
  76.       Top             =   480
  77.       Width           =   3780
  78.    End
  79.    Begin Label lblCourseName 
  80.       Alignment       =   2  'Center
  81.       BackStyle       =   0  'Transparent
  82.       Caption         =   "Course Name"
  83.       FontBold        =   0   'False
  84.       FontItalic      =   0   'False
  85.       FontName        =   "MS Sans Serif"
  86.       FontSize        =   9.75
  87.       FontStrikethru  =   0   'False
  88.       FontUnderline   =   0   'False
  89.       ForeColor       =   &H00800000&
  90.       Height          =   255
  91.       Left            =   180
  92.       TabIndex        =   15
  93.       Tag             =   "/3d_raised/"
  94.       Top             =   75
  95.       Width           =   6135
  96.    End
  97.    Begin Label lblInfo 
  98.       BackColor       =   &H00C0C0C0&
  99.       BorderStyle     =   1  'Fixed Single
  100.       Caption         =   "Double-click behind the ball to swing. Distance from the ball increases swing strength."
  101.       FontBold        =   0   'False
  102.       FontItalic      =   0   'False
  103.       FontName        =   "MS Sans Serif"
  104.       FontSize        =   8.25
  105.       FontStrikethru  =   0   'False
  106.       FontUnderline   =   0   'False
  107.       ForeColor       =   &H00800000&
  108.       Height          =   855
  109.       Left            =   4320
  110.       TabIndex        =   14
  111.       Tag             =   "/3d_inset/"
  112.       Top             =   1500
  113.       Width           =   1875
  114.    End
  115.    Begin Label Label5 
  116.       Alignment       =   2  'Center
  117.       BackStyle       =   0  'Transparent
  118.       BorderStyle     =   1  'Fixed Single
  119.       Caption         =   "Select a Club"
  120.       FontBold        =   0   'False
  121.       FontItalic      =   0   'False
  122.       FontName        =   "MS Sans Serif"
  123.       FontSize        =   8.25
  124.       FontStrikethru  =   0   'False
  125.       FontUnderline   =   0   'False
  126.       ForeColor       =   &H00800000&
  127.       Height          =   255
  128.       Left            =   4380
  129.       TabIndex        =   8
  130.       Tag             =   "/3d_raised/"
  131.       Top             =   4080
  132.       Width           =   1740
  133.    End
  134.    Begin Image imgClub 
  135.       BorderStyle     =   1  'Fixed Single
  136.       Height          =   645
  137.       Index           =   2
  138.       Left            =   5580
  139.       Picture         =   GOLF.FRX:0302
  140.       Top             =   4440
  141.       Width           =   525
  142.    End
  143.    Begin Image imgClub 
  144.       BorderStyle     =   1  'Fixed Single
  145.       Height          =   645
  146.       Index           =   1
  147.       Left            =   4980
  148.       Picture         =   GOLF.FRX:06B0
  149.       Top             =   4440
  150.       Width           =   525
  151.    End
  152.    Begin Image imgClub 
  153.       BorderStyle     =   1  'Fixed Single
  154.       Height          =   645
  155.       Index           =   0
  156.       Left            =   4380
  157.       Picture         =   GOLF.FRX:0A5E
  158.       Top             =   4440
  159.       Width           =   525
  160.    End
  161.    Begin Label Label6 
  162.       Alignment       =   2  'Center
  163.       BackStyle       =   0  'Transparent
  164.       Caption         =   "Score"
  165.       FontBold        =   0   'False
  166.       FontItalic      =   0   'False
  167.       FontName        =   "MS Sans Serif"
  168.       FontSize        =   9.75
  169.       FontStrikethru  =   0   'False
  170.       FontUnderline   =   0   'False
  171.       ForeColor       =   &H00800000&
  172.       Height          =   255
  173.       Left            =   4380
  174.       TabIndex        =   12
  175.       Tag             =   "/3d_raised/"
  176.       Top             =   3240
  177.       Width           =   1755
  178.    End
  179.    Begin Label lblScore 
  180.       Alignment       =   2  'Center
  181.       BackColor       =   &H0080FFFF&
  182.       BorderStyle     =   1  'Fixed Single
  183.       Caption         =   "0"
  184.       FontBold        =   -1  'True
  185.       FontItalic      =   0   'False
  186.       FontName        =   "MS Sans Serif"
  187.       FontSize        =   9.75
  188.       FontStrikethru  =   0   'False
  189.       FontUnderline   =   0   'False
  190.       ForeColor       =   &H00FF0000&
  191.       Height          =   255
  192.       Left            =   4380
  193.       TabIndex        =   11
  194.       Tag             =   "/3d_inset/"
  195.       Top             =   3600
  196.       Width           =   1755
  197.    End
  198.    Begin Label lblPar 
  199.       Alignment       =   2  'Center
  200.       BackColor       =   &H0080FFFF&
  201.       BorderStyle     =   1  'Fixed Single
  202.       Caption         =   "0"
  203.       FontBold        =   -1  'True
  204.       FontItalic      =   0   'False
  205.       FontName        =   "MS Sans Serif"
  206.       FontSize        =   9.75
  207.       FontStrikethru  =   0   'False
  208.       FontUnderline   =   0   'False
  209.       ForeColor       =   &H00FF0000&
  210.       Height          =   255
  211.       Left            =   5340
  212.       TabIndex        =   10
  213.       Tag             =   "/3d_inset/"
  214.       Top             =   1020
  215.       Width           =   855
  216.    End
  217.    Begin Label lblStrokes 
  218.       Alignment       =   2  'Center
  219.       BackColor       =   &H0080FFFF&
  220.       BorderStyle     =   1  'Fixed Single
  221.       Caption         =   "0"
  222.       FontBold        =   -1  'True
  223.       FontItalic      =   0   'False
  224.       FontName        =   "MS Sans Serif"
  225.       FontSize        =   9.75
  226.       FontStrikethru  =   0   'False
  227.       FontUnderline   =   0   'False
  228.       ForeColor       =   &H00FF0000&
  229.       Height          =   255
  230.       Left            =   4680
  231.       TabIndex        =   9
  232.       Tag             =   "/3d_inset/"
  233.       Top             =   2820
  234.       Width           =   1095
  235.    End
  236.    Begin Label lblHole 
  237.       Alignment       =   2  'Center
  238.       BackColor       =   &H0080FFFF&
  239.       BorderStyle     =   1  'Fixed Single
  240.       Caption         =   "0"
  241.       FontBold        =   -1  'True
  242.       FontItalic      =   0   'False
  243.       FontName        =   "MS Sans Serif"
  244.       FontSize        =   9.75
  245.       FontStrikethru  =   0   'False
  246.       FontUnderline   =   0   'False
  247.       ForeColor       =   &H00FF0000&
  248.       Height          =   255
  249.       Left            =   4320
  250.       TabIndex        =   7
  251.       Tag             =   "/3d_inset/"
  252.       Top             =   1020
  253.       Width           =   855
  254.    End
  255.    Begin Label Label4 
  256.       Alignment       =   2  'Center
  257.       BackStyle       =   0  'Transparent
  258.       Caption         =   "Strokes"
  259.       FontBold        =   0   'False
  260.       FontItalic      =   0   'False
  261.       FontName        =   "MS Sans Serif"
  262.       FontSize        =   9.75
  263.       FontStrikethru  =   0   'False
  264.       FontUnderline   =   0   'False
  265.       ForeColor       =   &H00800000&
  266.       Height          =   255
  267.       Left            =   4680
  268.       TabIndex        =   4
  269.       Tag             =   "/3d_raised/"
  270.       Top             =   2460
  271.       Width           =   1095
  272.    End
  273.    Begin Label Label3 
  274.       Alignment       =   2  'Center
  275.       BackStyle       =   0  'Transparent
  276.       Caption         =   "Par"
  277.       FontBold        =   0   'False
  278.       FontItalic      =   0   'False
  279.       FontName        =   "MS Sans Serif"
  280.       FontSize        =   9.75
  281.       FontStrikethru  =   0   'False
  282.       FontUnderline   =   0   'False
  283.       ForeColor       =   &H00800000&
  284.       Height          =   255
  285.       Left            =   5340
  286.       TabIndex        =   3
  287.       Tag             =   "/3d_raised/"
  288.       Top             =   660
  289.       Width           =   855
  290.    End
  291.    Begin Label Label1 
  292.       Alignment       =   2  'Center
  293.       BackStyle       =   0  'Transparent
  294.       Caption         =   "Hole"
  295.       FontBold        =   0   'False
  296.       FontItalic      =   0   'False
  297.       FontName        =   "MS Sans Serif"
  298.       FontSize        =   9.75
  299.       FontStrikethru  =   0   'False
  300.       FontUnderline   =   0   'False
  301.       ForeColor       =   &H00800000&
  302.       Height          =   255
  303.       Left            =   4320
  304.       TabIndex        =   1
  305.       Tag             =   "/3d_raised/"
  306.       Top             =   660
  307.       Width           =   855
  308.    End
  309.    Begin Shape Shape1 
  310.       BorderColor     =   &H000000FF&
  311.       BorderWidth     =   4
  312.       Height          =   660
  313.       Left            =   4380
  314.       Top             =   4440
  315.       Width           =   540
  316.    End
  317.    Begin Label lblFrame1 
  318.       BackStyle       =   0  'Transparent
  319.       ForeColor       =   &H00C0C0C0&
  320.       Height          =   4755
  321.       Left            =   4200
  322.       TabIndex        =   5
  323.       Tag             =   "/3d_inset/"
  324.       Top             =   480
  325.       Width           =   2115
  326.    End
  327. Option Explicit
  328. '------------------------------------------------------------
  329. ' Constants and module-level variables used in GOLF.MAK
  330. '------------------------------------------------------------
  331. ' Valid game states.
  332. Const GAME_OVER = 0
  333. Const GAME_IN_PROGRESS = 1
  334. ' Available clubs (we travel light).
  335. Const CLUB_DRIVER = 0
  336. Const CLUB_IRON = 1
  337. Const CLUB_PUTTER = 2
  338. ' The ball's coordinates.
  339. Dim mBall As tLocation
  340. Dim mMouse As tLocation
  341. Dim mDelta As tLocation
  342. ' An array of structures defining individual
  343. ' holes in the course.
  344. Dim mHole(1 To 18) As tHole
  345. ' The actual number of holes in the
  346. ' current course.
  347. Dim mNumHoles As Integer
  348. ' The available clubs.
  349. Dim mClubFactor(0 To 2)  As Integer
  350. Dim mClubNumber As Integer
  351. Dim mGameState As Integer
  352. ' The total par for the course so far;
  353. ' used for displaying score.
  354. Dim mTotalPar As Integer
  355. Sub btnHelp_Click ()
  356. '------------------------------------------------------------
  357. ' Display the help screen.
  358. '------------------------------------------------------------
  359. Const SHOW_MODAL = 1
  360.     frmAboutGolf.Show SHOW_MODAL
  361. End Sub
  362. Sub btnNewGame_Click ()
  363. '------------------------------------------------------------
  364. ' Reset everything for a new game.
  365. '------------------------------------------------------------
  366.     mGameState = GAME_IN_PROGRESS
  367.     mTotalPar = 0
  368.     lblScore = "0 - Par"
  369.     SetupHole 1
  370. End Sub
  371. Sub btnQuit_Click ()
  372. '------------------------------------------------------------
  373. ' Exit the program.
  374. '------------------------------------------------------------
  375.     Unload Me
  376. End Sub
  377. Sub DrawBall ()
  378. '------------------------------------------------------------
  379. ' Redraw the ball at its current x-y position.
  380. '------------------------------------------------------------
  381.     picBG.Cls
  382.     picBG.DrawWidth = 2
  383.     picBG.PSet (mBall.x, mBall.y), MAGENTA
  384.     picBG.DrawWidth = 1
  385. End Sub
  386. Sub Form_Load ()
  387. '------------------------------------------------------------
  388. ' Read the game data and set up the first game.
  389. '------------------------------------------------------------
  390.     Randomize
  391.     AppPath = App.Path
  392.     If Right$(AppPath, 1) <> "\" Then AppPath = AppPath & "\"
  393.     ReadGameData
  394.     InitClubs
  395.     Me.Show
  396.     CenterForm Me
  397.     Paint3D Me
  398.     Pause 1
  399.     btnNewGame_Click
  400. End Sub
  401. Function GetLocationByColor (AColor As Long) As String
  402. '------------------------------------------------------------
  403. ' Given a color, return a string indicating what that color
  404. ' corresponds to.
  405. '------------------------------------------------------------
  406. Dim i As Integer
  407.     Select Case AColor
  408.         Case RED: GetLocationByColor = "HOLE"
  409.         Case BLUE, DK_BLUE, DK_CYAN: GetLocationByColor = "WATER"
  410.         Case WHITE, YELLOW: GetLocationByColor = "SANDTRAP"
  411.         Case Else
  412.             GetLocationByColor = ""
  413.     End Select
  414. End Function
  415. Sub imgClub_Click (Index As Integer)
  416. '------------------------------------------------------------
  417. ' Select a new club.
  418. '------------------------------------------------------------
  419.     Shape1.Move imgClub(Index).Left, imgClub(Index).Top
  420.     mClubNumber = Index
  421. End Sub
  422. Function InHole (x As Integer, y As Integer) As Integer
  423. '------------------------------------------------------------
  424. ' Return True if this x-y location is in the hole, false
  425. ' otherwise.
  426. '------------------------------------------------------------
  427. Dim DC As Integer
  428.     DC = picReference.hDC
  429.     If GetPixel(DC, x, y) = RED Or GetPixel(DC, x + 1, y) = RED Then
  430.         InHole = True
  431.     ElseIf GetPixel(DC, x, y - 1) = RED Or GetPixel(DC, x + 1, y - 1) = RED Then
  432.         InHole = True
  433.     ElseIf GetPixel(DC, x, y + 1) = RED Or GetPixel(DC, x + 1, y + 1) = RED Then
  434.         InHole = True
  435.     Else
  436.         InHole = False
  437.     End If
  438. End Function
  439. Sub InitClubs ()
  440. '------------------------------------------------------------
  441. ' Set the club factor array.  This determines the distance
  442. ' that the ball will go when hit wil a particular type of
  443. ' club.
  444. '------------------------------------------------------------
  445.     mClubFactor(CLUB_DRIVER) = 8
  446.     mClubFactor(CLUB_IRON) = 3
  447.     mClubFactor(CLUB_PUTTER) = 1
  448. End Sub
  449. Function OutOfBounds (x As Integer, y As Integer) As Integer
  450. '------------------------------------------------------------
  451. ' Returns True if the x-y coordinate is outside the bitmap.
  452. '------------------------------------------------------------
  453. Dim BoundsMargin As Integer
  454.     BoundsMargin = 4
  455.     OutOfBounds = False
  456.     If (x < BoundsMargin) Or (x > picBG.ScaleWidth - BoundsMargin) Or (y < BoundsMargin) Or (y > picBG.ScaleHeight - BoundsMargin) Then
  457.         OutOfBounds = True
  458.     End If
  459. End Function
  460. Sub picBG_DblClick ()
  461. '------------------------------------------------------------
  462. ' Hit the ball.  This is where most of the action happens.
  463. '------------------------------------------------------------
  464. Dim rc As Integer
  465. Dim slope As Single
  466. Dim Dist As Single
  467. Dim MaxDist As Single
  468. Dim direct As tLocation
  469. Dim i As Integer
  470. Dim xf As Single, yf As Single
  471. Dim OK As Integer
  472. Dim BG_Color As Long
  473. Dim Location As String
  474. Dim PauseFactor As Single
  475. Dim InTree As Integer
  476. Dim InSandTrap As Integer
  477. Dim Temp As tLocation
  478. Dim MoveDir As Integer
  479. Dim WaveFileName As String
  480.     ' Can't hit the ball if you're not playing a game.
  481.     If mGameState = GAME_OVER Then Exit Sub
  482.     InTree = False
  483.     lblInfo = "Double-click behind the ball to swing. "
  484.     lblInfo = lblInfo & "Distance from the ball increases swing strength."
  485.     mDelta.x = mBall.x - mMouse.x
  486.     If mDelta.x = 0 Then mDelta.x = 1
  487.     mDelta.y = mBall.y - mMouse.y
  488.     MaxDist = Sqr(mDelta.x ^ 2 + mDelta.y ^ 2) * mClubFactor(mClubNumber)
  489.     ' If this is the player's first shot, they're on the tee, so
  490.     ' they can hit a bit farther.
  491.     If lblStrokes > 0 Then
  492.         If MaxDist > (picBG.ScaleHeight / 3) Then MaxDist = picBG.ScaleHeight / 3
  493.     End If
  494.     ' Bump up strokes
  495.     lblStrokes = lblStrokes + 1
  496.     ' What color is the ball over?
  497.     BG_Color = GetPixel(picReference.hDC, mBall.x, mBall.y)
  498.     ' Are we in a tree?
  499.     If (BG_Color = BLACK) Or (BG_Color = BROWN) Then
  500.         InTree = True
  501.         MaxDist = 2 * mClubFactor(mClubNumber)
  502.     End If
  503.     ' In a sand trap...
  504.     If (BG_Color = WHITE) Or (BG_Color = YELLOW) Then
  505.         ' If they want to make any progress, they'd better
  506.         ' use the iron.
  507.         If mClubNumber = CLUB_IRON Then
  508.             MaxDist = MaxDist * .75
  509.         Else
  510.             MaxDist = 2
  511.         End If
  512.     End If
  513.     slope = Abs(mDelta.y / mDelta.x)
  514.     If mDelta.x > 0 Then
  515.         direct.x = 1
  516.     ElseIf mDelta.x < 0 Then
  517.         direct.x = -1
  518.     Else
  519.         direct.x = 0
  520.     End If
  521.     If mDelta.y > 0 Then
  522.         direct.y = 1
  523.     ElseIf mDelta.y < 0 Then
  524.         direct.y = -1
  525.     Else
  526.         direct.y = 0
  527.     End If
  528.     xf = mBall.x
  529.     yf = mBall.y
  530.     OK = True
  531.     i = 0
  532.     picBG.CurrentX = mBall.x
  533.     picBG.CurrentY = mBall.y
  534.     ' Pick the appropriate sound for the club used.
  535.     Select Case mClubNumber
  536.         Case CLUB_DRIVER: WaveFileName = "SWING1.WAV"
  537.         Case CLUB_IRON: WaveFileName = "SWING2.WAV"
  538.         Case CLUB_PUTTER: WaveFileName = "SWING3.WAV"
  539.     End Select
  540.     rc = sndPlaySound(AppPath & WaveFileName, SND_ASYNC)
  541.     Pause .25
  542.     PauseFactor = .001 * Abs(mDelta.y * 1.85)
  543.     ' Draw the ball as it moves, showing its trajectory.
  544.     While OK
  545.         i = i + 1
  546.         xf = xf + direct.x
  547.         yf = yf + (slope * direct.y)
  548.         Dist = Sqr(CInt(mBall.x - xf) ^ 2 + CInt(mBall.y - yf) ^ 2)
  549.         If Dist >= MaxDist Then OK = False
  550.         picBG.Line -(CInt(xf), CInt(yf)), QBColor(4)
  551.         Pause PauseFactor
  552.         BG_Color = GetPixel(picReference.hDC, CInt(xf), CInt(yf))
  553.         
  554.         ' Yikes! Out of Bounds!
  555.         If OutOfBounds(CInt(xf), CInt(yf)) Then
  556.             lblStrokes = lblStrokes + 2
  557.             If CInt(Rnd * 2) = 1 Then
  558.                 lblInfo = "Your ball went out of bounds (and hit the club house).  Two stroke penalty."
  559.                 rc = sndPlaySound(AppPath & "OUTOBND1.WAV", SND_ASYNC)
  560.             Else
  561.                 lblInfo = "Your ball went out of bounds (and hit a by-stander).  Two stroke penalty."
  562.                 rc = sndPlaySound(AppPath & "OUTOBND2.WAV", SND_ASYNC)
  563.             End If
  564.             DrawBall
  565.             Exit Sub
  566.         End If
  567.         
  568.         ' Oops! Hit a Tree!
  569.         If (BG_Color = BLACK) And (Not InTree) Then
  570.             rc = sndPlaySound(AppPath & "TREEHIT.WAV", SND_ASYNC)
  571.             OK = False
  572.         End If
  573.         
  574.         ' In the Hole!
  575.         If InHole(CInt(xf), CInt(yf)) Then
  576.             rc = sndPlaySound(AppPath & "INHOLE.WAV", SND_SYNC)
  577.             
  578.             ' Scoring...
  579.             lblScore = CInt(Left(lblScore, InStr(lblScore, " ") - 1)) + lblStrokes
  580.             mTotalPar = mTotalPar + lblPar
  581.             If lblScore > mTotalPar Then
  582.                 lblScore = Format$(lblScore) & " - " & Format$(lblScore - mTotalPar) & " over par"
  583.             ElseIf lblScore < mTotalPar Then
  584.                 lblScore = Format$(lblScore) & " - " & Format$(mTotalPar - lblScore) & " under par"
  585.             Else
  586.                 lblScore = Format$(lblScore) & " - Par"
  587.             End If
  588.             If lblHole = mNumHoles Then
  589.                 mGameState = GAME_OVER
  590.                 rc = sndPlaySound(AppPath & "APPLAUS2.WAV", SND_ASYNC)
  591.                 Exit Sub
  592.             Else
  593.                 SetupHole lblHole + 1
  594.                 Exit Sub
  595.             End If
  596.         End If
  597.     Wend
  598.     mBall.x = CInt(xf)
  599.     mBall.y = CInt(yf)
  600.     ' Where is the ball?
  601.     BG_Color = GetPixel(picReference.hDC, mBall.x, mBall.y)
  602.     Location = GetLocationByColor(BG_Color)
  603.     ' Did it land in the water?
  604.     If Location = "WATER" Then
  605.         Temp.x = mBall.x
  606.         Temp.y = mBall.y
  607.         lblInfo = "One stroke penalty for going in the water hazard."
  608.         lblStrokes = lblStrokes + 1
  609.         rc = sndPlaySound(AppPath & "SPLASH.WAV", SND_ASYNC)
  610.         If mBall.x > (picBG.ScaleWidth / 2) Then
  611.             MoveDir = -5
  612.         Else
  613.             MoveDir = 5
  614.         End If
  615.         While ((BG_Color = BLUE) Or (BG_Color = DK_BLUE) Or (BG_Color = DK_CYAN))
  616.             Temp.x = Temp.x + MoveDir
  617.             picBG.Line -(Temp.x, Temp.y), YELLOW
  618.             Pause .25
  619.             
  620.             BG_Color = GetPixel(picReference.hDC, Temp.x, Temp.y)
  621.         Wend
  622.         mBall.x = Temp.x
  623.     ' Did it land in a sand trap?
  624.     ElseIf Location = "SANDTRAP" Then
  625.         lblInfo = "You're in a bunker."
  626.         rc = sndPlaySound(AppPath & "BUNKER2.WAV", SND_ASYNC)
  627.     End If
  628.     DrawBall
  629. End Sub
  630. Sub picBG_MouseMove (Button As Integer, Shift As Integer, x As Single, y As Single)
  631. '------------------------------------------------------------
  632. ' Keep track of the mouse's position.
  633. '------------------------------------------------------------
  634.     mMouse.x = x
  635.     mMouse.y = y
  636. End Sub
  637. Sub ReadGameData ()
  638. '------------------------------------------------------------
  639. ' Read the GAMEINFO.TXT file, and build the data structures
  640. ' that define the holes.
  641. '------------------------------------------------------------
  642. Dim fnum As Integer
  643. Dim ALine As String
  644. Dim HoleNum As Integer
  645. Dim DefaultTee As tLocation
  646. Dim DefaultPar As Integer
  647. Dim ID As String
  648.     On Error Resume Next
  649.     DefaultTee.x = picBG.ScaleWidth \ 2
  650.     DefaultTee.y = picBG.ScaleHeight - 50
  651.     DefaultPar = 5
  652.     fnum = FreeFile
  653.     Open AppPath & "GAMEINFO.TXT" For Input As fnum
  654.     If Err > 0 Then
  655.         MsgBox "Couldn't find the game definition file.", MB_OK Or MB_ICONEXCLAMATION, "Golf"
  656.         Unload Me
  657.     End If
  658.     HoleNum = 0
  659.     While Not EOF(fnum)
  660.         Line Input #fnum, ALine
  661.         ALine = Trim$(ALine)
  662.         If UCase$(ALine) = "NEW HOLE" Then
  663.             HoleNum = HoleNum + 1
  664.         Else
  665.             ID = Trim$(UCase$(PopField(ALine, ":")))
  666.             Select Case ID
  667.                 Case "COURSE":
  668.                     lblCourseName = Trim$(ALine)
  669.                 Case "FILE":
  670.                     mHole(HoleNum).FileName = Trim$(ALine)
  671.                 Case "TEE":
  672.                     mHole(HoleNum).Tee.x = CInt(PopField(ALine, ","))
  673.                     If Err > 0 Then mHole(HoleNum).Tee.x = DefaultTee.x
  674.                     mHole(HoleNum).Tee.y = CInt(ALine)
  675.                     If Err > 0 Then mHole(HoleNum).Tee.y = DefaultTee.y
  676.                 Case "PAR"
  677.                     mHole(HoleNum).Par = CInt(ALine)
  678.                     If Err > 0 Then mHole(HoleNum).Par = DefaultPar
  679.             End Select
  680.         End If
  681.     Wend
  682.     Close fnum
  683.     mNumHoles = HoleNum
  684.     On Error GoTo 0
  685. End Sub
  686. Sub SetupHole (ByVal HoleNum As Integer)
  687. '------------------------------------------------------------
  688. ' Set up a new hole: draw the background, reset labels, and
  689. ' place the ball on the tee.
  690. '------------------------------------------------------------
  691. Dim x As Integer
  692. Dim BltLeft As Integer
  693. Dim rc As Integer
  694.     On Error Resume Next
  695.     picReference.Picture = LoadPicture(AppPath & mHole(HoleNum).FileName)
  696.     If Err > 0 Then
  697.         MsgBox "Couldn't find bitmap for Hole " & Format$(HoleNum) & "!", MB_OK Or MB_ICONSTOP, "Golf"
  698.         End
  699.     End If
  700.     ' Slide the background in from the right, with sound effects.
  701.     rc = sndPlaySound(AppPath & "SLIDE.WAV", SND_ASYNC)
  702.     picBG.AutoRedraw = False
  703.     For x = 2 To picBG.ScaleWidth
  704.         BltLeft = picBG.ScaleWidth - x
  705.         rc = BitBlt(picBG.hDC, BltLeft, 0, x, picBG.ScaleHeight, picReference.hDC, 0, 0, SRCCOPY)
  706.         Pause .001
  707.     Next
  708.     picBG.AutoRedraw = True
  709.     picBG.Picture = picReference.Picture
  710.     ' Initialize variables for this hole.
  711.     lblHole = HoleNum
  712.     lblPar = mHole(lblHole).Par
  713.     mBall.x = mHole(lblHole).Tee.x
  714.     mBall.y = mHole(lblHole).Tee.y
  715.     lblStrokes = 0
  716.     DrawBall
  717.     ' The default club will be a driver.
  718.     imgClub_Click CLUB_DRIVER
  719. End Sub
  720.